home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.11 Nov 91 / TPose Source / PostRes() < prev    next >
Encoding:
Text File  |  1991-05-17  |  5.9 KB  |  204 lines  |  [TEXT/MPS ]

  1.  
  2. {-----------------------------------------------------------------------------------------}
  3. Add to UMacApp.p:
  4.                 PROCEDURE TView.PostRes;
  5.                 { Called on each view created by DoCreateViews(), in a post-order traversal,
  6.                 view creation is completed. }
  7. {-----------------------------------------------------------------------------------------}
  8.                 
  9. {-----------------------------------------------------------------------------------------}
  10. Change in UMacApp.TEvtHandler.p (thanks to John MacVeigh):
  11. {-----------------------------------------------------------------------------------------}
  12. FUNCTION TEvtHandler.DoCreateViews(itsDocument: TDocument;
  13.                                    parentView: TView;
  14.                                    itsRsrcID: INTEGER;
  15.                                    subviewOffset: VPoint): TView;
  16.  
  17. Var   TopView: TView;
  18.  
  19.  
  20.     {-------------------------------------------------------------------------------------}
  21.     
  22.     Procedure CallPostRes (aView: TView);
  23.     {perform a (rather convoluted) post-order traversal of the
  24.      subview lists, such that a view's subviews will all have
  25.      PostRes called before the view itself is PosRes'd.}
  26.  
  27.     Var   Unused: ArrayIndex;
  28.  
  29.         Function DummyTest (item: TView): Boolean;
  30.         Begin
  31.             CallPostRes (Item);
  32.             DummyTest := False
  33.         End;
  34.  
  35.     Begin
  36.         If aView.fSubViews <> Nil Then
  37.             If aView.fSubViews.IterateTil (DummyTest, kIterateBackward, Unused) <> Nil Then;
  38.  
  39.         aView.PostRes
  40.     End;   {CallPostRes}
  41.     
  42.     {-------------------------------------------------------------------------------------}
  43.  
  44.     { JLP: "ReallyDoCreateViews" is original (MacApp 2.0 Final) DoCreateViews() }
  45.  
  46.     {-------------------------------------------------------------------------------------}
  47.     Function ReallyDoCreateViews(itsDocument: TDocument;
  48.                                    parentView: TView;
  49.                                    itsRsrcID: INTEGER;
  50.                                    subviewOffset: VPoint): TView;
  51.  
  52.     VAR
  53.         i:                    INTEGER;
  54.         numViews:            INTEGER;
  55.         aView:                TView;
  56.         viewResource:        ViewRsrcHndl;
  57.         theViewInfo:        ViewTemplatePtr;
  58.         lastParentID:        IDType;
  59.         lastParent:         TView;
  60.         lastRoot:            TView;
  61.         firstView:        TView;
  62.         fi:                 FailInfo;
  63.  
  64.     PROCEDURE HdlDoCreateViews(error: OSErr;
  65.                                message: LONGINT);
  66.  
  67.         BEGIN
  68.         IF viewResource <> NIL THEN                     { Don't constipate the heap }
  69.             HUnLock(Handle(viewResource));
  70.  
  71.         FreeIfObject(firstView);
  72.         firstView := NIL;
  73.         END;
  74.  
  75.     {$IFC qDebug}
  76.  
  77.     PROCEDURE ReportTemplate;
  78.  
  79.         BEGIN
  80.         WITH theViewInfo^ DO
  81.             BEGIN
  82.             WrLblSig('signature', itsSignature);
  83.             WriteLn;
  84.             WrLblSig('itsParentID', itsParentID);
  85.             WrLblSig(', thisViewID', thisViewID);
  86.             WriteLn;
  87.             WrLblVPt('itsLocation', itsLocation);
  88.             WrLblVPt(', itsSize', itsSize);
  89.             Write('itsHSizeDet = ', ord(itsHSizeDet): 3);
  90.             WriteLn(', itsVSizeDet = ', ord(itsVSizeDet): 3);
  91.             WrLblBoolean(', isEnabled ', isEnabled);
  92.             WriteLn;
  93.             WriteLn('----------  end of view  ----------');
  94.             END;
  95.         END;
  96.     {$ENDC}
  97.  
  98.     BEGIN
  99.         firstView := NIL;                                { Assume the worst. }
  100.  
  101.         viewResource := ViewRsrcHndl(GetResource('view', itsRsrcID));
  102.         IF viewResource = NIL THEN
  103.             BEGIN
  104.             {$IFC qDebug}
  105.             ProgramBreak(ConcatNumber('Unable to find ‘view’ resource #', itsRsrcID));
  106.             {$ENDC}
  107.             FailNilResource(viewResource);
  108.             END;
  109.  
  110.         LockHandleHigh(Handle(viewResource));
  111.  
  112.         CatchFailures(fi, HdlDoCreateViews);
  113.  
  114.         numViews := viewResource^^.numViews;
  115.         theViewInfo := @viewResource^^.theViews;
  116.         lastParentID := kNoIdentifier;
  117.         aView := parentView;
  118.         lastRoot := parentView;
  119.  
  120.         FOR i := 1 TO numViews DO
  121.             WITH theViewInfo^ DO
  122.                 BEGIN
  123.                 {$IFC qDebug}
  124.                 IF gIntenseDebugging THEN
  125.                     ReportTemplate;
  126.                 {$ENDC}
  127.  
  128.                 IF LONGINT(itsParentID) = LONGINT(kNoIdentifier) THEN
  129.                     lastParent := parentView
  130.                 ELSE IF LONGINT(itsParentID) <> LONGINT(lastParentID) THEN
  131.                     BEGIN
  132.                     lastParent := aView;                { Begin with last view created or parentView
  133.                                                          }
  134.                     WHILE (lastParent <> NIL) & (lastParent.fIdentifier <> itsParentID) DO
  135.                         lastParent := lastParent.fSuperView;
  136.  
  137.                     IF (lastParent = NIL) & (lastRoot <> NIL) THEN
  138.                         IF aView <> NIL THEN
  139.                             lastParent := aView.FindSubView(itsParentID)
  140.                         ELSE
  141.                             lastParent := lastRoot.FindSubView(itsParentID);
  142.  
  143.                     {$IFC qDebug}
  144.                     IF lastParent = NIL THEN
  145.                         ProgramBreak('Unable to find parent view for template');
  146.                     {$ENDC}
  147.                     END;
  148.                 lastParentID := itsParentID;
  149.  
  150.                 IF LONGINT(itsSignature) = LONGINT('incl') THEN
  151.                     BEGIN
  152.                     aView := ReallyDoCreateViews(itsDocument, lastParent, includeRsrcID, gZeroVPt);
  153.                     OffsetPtr(theViewInfo, SIZEOF(ViewTemplate) - SIZEOF(Str255) + SIZEOF(INTEGER));
  154.                     END
  155.                 ELSE IF LONGINT(itsSignature) = LONGINT('inc@') THEN
  156.                     BEGIN
  157.                     aView := ReallyDoCreateViews(itsDocument, lastParent, includeRsrcID,
  158.                              itsSubViewOffset);
  159.                     OffsetPtr(theViewInfo, SIZEOF(ViewTemplate) - SIZEOF(Str255) +
  160.                               SIZEOF(INTEGER) + SIZEOF(VPoint));
  161.                     END
  162.                 ELSE
  163.                     aView := CreateAView(itsDocument, lastParent, Ptr(theViewInfo));
  164.  
  165.                 IF aView = NIL THEN
  166.                     LEAVE;
  167.                 IF ((subviewOffset.h <> 0) | (subviewOffset.v <> 0)) & (aView.fSuperView =
  168.                    parentView) & (parentView <> NIL) THEN
  169.                     aView.Locate(aView.fLocation.h + subviewOffset.h, aView.fLocation.v +
  170.                                  subviewOffset.v, kDontInvalidate);
  171.  
  172.                 IF i = 1 THEN
  173.                     BEGIN
  174.                     firstView := aView;
  175.                     IF Member(aView, TWindow) & (parentView = NIL) THEN
  176.                         parentView := aView;
  177.                     END;
  178.  
  179.                 IF (lastRoot = NIL) & (aView <> NIL) & (aView.fSuperView = NIL) THEN
  180.                     lastRoot := aView;
  181.                 END;
  182.  
  183.         HUnLock(Handle(viewResource));
  184.         Success(fi);
  185.  
  186.         ReallyDoCreateViews := firstView    {*** what DoCreateViews used to return}
  187.     End;   {ReallyDoCreateViews}
  188.  
  189. Begin  {DoCreateViews}
  190.     If fNextHandler <> Nil
  191.         Then DoCreateViews := fNextHandler.DoCreateViews
  192.                                                                     (itsDocument, parentView, itsRsrcID, subviewOffset)
  193.         Else Begin
  194.             TopView := ReallyDoCreateViews (itsDocument, parentView, itsRsrcID, subviewOffset);
  195.  
  196.             If TopView <> Nil Then Begin
  197.                 CallPostRes (TopView);
  198.  
  199.                 TopView.AdjustSize;        { Make sure size gets adjusted by the size determiners }
  200.             End;
  201.  
  202.             DoCreateViews := TopView
  203.         End
  204. End;   {DoCreateViews}